﻿using Common.Contract.Authentication.Record;
using Common.Type;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace SMEsCustomer360Degree.Core.Configuration
{
    public static class SystemConfiguration
    {
        private static Guid applicationKey;
        public static Guid ApplicationKey
        {
            get
            {
                if (applicationKey != Guid.Empty) return applicationKey;
                var key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x == "ApplicationKey");

                if (!string.IsNullOrEmpty(key) && Guid.TryParse(ConfigurationManager.AppSettings[key], out applicationKey))
                    return applicationKey;

                return Guid.Empty;
            }
        }
        private static string supperAdmin;
        public static string SUPPER_ADMIN
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(supperAdmin)) return supperAdmin;
                var key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x.ToUpper() == "SUPPER_ADMIN");
                if (!string.IsNullOrEmpty(key)) supperAdmin = ConfigurationManager.AppSettings[key];
                if (string.IsNullOrWhiteSpace(supperAdmin)) return "SYSADMIN";
                supperAdmin = supperAdmin.ToUpper();
                return supperAdmin;
            }
        }


        private static int defaultCacheTime = 0;
        public static int DefaultCacheTime
        {
            get
            {
                if (defaultCacheTime > 0) return defaultCacheTime;
                if (!int.TryParse(ConfigurationManager.AppSettings["DefaultCacheTime"], out defaultCacheTime))
                {
                    defaultCacheTime = 5;
                }
                return defaultCacheTime;
            }
        }

        private static List<ObjectRecord> listMenuHeader = new List<ObjectRecord>();
        public static List<ObjectRecord> ListMenuHeader
        {
            get
            {
                ObjectRecord imex = new ObjectRecord
                {
                    ObjectName = "IM & EX CUSTOMERS",
                    ObjectUrl = "/imex/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(imex);
                ObjectRecord cus_detail = new ObjectRecord
                {
                    ObjectName = "CUSTOMER DETAIL",
                    ObjectUrl = "/customerdetail/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(cus_detail);
                ObjectRecord alert = new ObjectRecord
                {
                    ObjectName = "ALERT",
                    ObjectUrl = "/alert/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(alert);
                ObjectRecord sal_act = new ObjectRecord
                {
                    ObjectName = "SALE ACTIVITY",
                    ObjectUrl = "/saleactivity/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(sal_act);
                ObjectRecord port_mana = new ObjectRecord
                {
                    ObjectName = "PORTFOLIO MANAGEMENT",
                    ObjectUrl = "/portfoliomanagement/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(port_mana);
                ObjectRecord sal_perfom = new ObjectRecord
                {
                    ObjectName = "SALE PERFORMANCE",
                    ObjectUrl = "/saleperformance/deposit",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(sal_perfom);
                ObjectRecord cus_manager = new ObjectRecord
                {
                    ObjectName = "CUSTOMERS MANAGER",
                    ObjectUrl = "/",
                    ObjectIcon = ""
                };
                listMenuHeader.Add(cus_manager);
                return listMenuHeader;
            }
        }
        private static string roleLinkAccess;
        public static string RoleLinkAccess
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(roleLinkAccess)) return roleLinkAccess;
                roleLinkAccess = ConfigurationManager.AppSettings["RoleLinkAccess"];
                if (string.IsNullOrWhiteSpace(roleLinkAccess))
                {
                    roleLinkAccess = "ROLE15";
                }
                return roleLinkAccess;
            }
        }


        private static string roleLinkAccessKey;
        public static string RoleLinkAccessKey
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(roleLinkAccessKey)) return roleLinkAccessKey;
                roleLinkAccessKey = ConfigurationManager.AppSettings["RoleLinkAccessKey"];
                if (string.IsNullOrWhiteSpace(roleLinkAccessKey))
                {
                    roleLinkAccessKey = "ROLE_LINK_ACCESS_KEY";
                }
                return roleLinkAccessKey;
            }
        }
    }
}
